package com.zhijian.wharf.controller.web;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.wharf.annotation.LogOperation;
import com.zhijian.wharf.entity.po.ThirdPartyDocking;
import com.zhijian.wharf.entity.vo.request.ThirdPartyDockingSaveOrUpdateVo;
import com.zhijian.wharf.entity.vo.request.ThirdPartyDockingSearchVo;
import com.zhijian.wharf.entity.vo.response.ThirdPartyDockingVo;
import com.zhijian.wharf.enums.ThirdPartyDockingStatusEnum;
import com.zhijian.wharf.service.ThirdPartyDockingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 第三方对接 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-07-07 13:34:55
 */
@Slf4j
@Controller
@Api(tags = "第三方对接")
public class ThirdPartyDockingController {

    @Autowired
    private ThirdPartyDockingService service;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/third/party/docking")
    @ApiOperation("新增")
    @LogOperation("新增第三方")
    public ThirdPartyDocking insert(@RequestBody ThirdPartyDockingSaveOrUpdateVo param) {
        //默认通过
        param.setStatus(ThirdPartyDockingStatusEnum.PASS.getCode().byteValue());
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.save(param);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/third/party/docking/{id}")
    @ApiOperation("删除")
    @LogOperation("删除第三方")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

//    /**
//     * 修改
//     *
//     * @param id
//     * @param param
//     * @return
//     */
//    @Response
//    @PutMapping("/third/party/docking/{id}")
//    @ApiOperation("修改")
//    public boolean update(@PathVariable("id") Long id, @RequestBody ThirdPartyDockingSaveOrUpdateVo param) {
//        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
//        param.setId(id);
//        return service.modify(param);
//    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/third/party/docking/{id}")
    @ApiOperation("根据id查询")
    @LogOperation("查询第三方详情")
    public ThirdPartyDockingVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/third/party/docking/page")
    @ApiOperation("分页查询")
    @LogOperation("分页查询部门")
    public Page<ThirdPartyDockingVo> selectByCondition(@RequestBody(required = false) ThirdPartyDockingSearchVo param) {
        if (param == null)
            param = ThirdPartyDockingSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/third/party/docking/list")
    @ApiOperation("列表查询")
    @LogOperation("列表查询部门")
    public List<ThirdPartyDockingVo> selectList(@RequestBody(required = false) ThirdPartyDockingSearchVo param) {
        if (param == null)
            param = ThirdPartyDockingSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }

    /**
     * 审核
     *
     * @param id
     * @param approveStatus
     * @return
     */
    @Response
    @PostMapping("/third/party/docking/approve/{id}/{approveStatus}")
    @ApiOperation("审核")
    @LogOperation("审核第三方部门")
    public boolean approve(@ApiParam(name = "id", value = "ID", required = true)
                           @PathVariable("id") Long id,
                           @ApiParam(name = "approveStatus", value = "审核结果，1：已通过，2：已拒绝", required = true)
                           @PathVariable("approveStatus") Byte approveStatus) {
        return service.approve(id, approveStatus);
    }

    /**
     * 注册
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/third/party/docking/register")
    @ApiOperation("注册")
    @LogOperation("注册第三方")
    public boolean register(@RequestBody ThirdPartyDockingSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.register(param);
    }

}